package com.cib.leetcode.medium.sliding;

import java.util.HashSet;
import java.util.Set;

/**
 * 给定一个字符串 s ，请你找出其中不含有重复字符的最长子串的长度。
 *
 * @author goomba
 **/
public class Function03 {

    public int lengthOfLongestSubstring(String s) {
        if (null == s || s.isEmpty()) return 0;

        Set<Character> set = new HashSet<>();
        int maxLength = 0;

        for (int left = 0, right = 0; right < s.length(); right++) {
            Character curChar = s.charAt(right);
            while (set.contains(curChar)) {
                set.remove(s.charAt(left));
                left++;
            }
            set.add(curChar);
            maxLength = Math.max(maxLength, right - left + 1);
        }
        return maxLength;
    }
}
